package com.depth.viewer.request.remoteobject
{
	import com.depth.viewer.request.RequestBaseProxy;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	public class RemoteObjectRquest extends RequestBaseProxy
	{
		private var _remoteOjbect:RemoteObject = new RemoteObject();
		public function RemoteObjectRquest(destination:String=null,source:String = null)
		{
			super(destination);
			if(destination)
				_remoteOjbect.destination = destination;
			if(source)
				_remoteOjbect.source = source;
			
			_remoteOjbect.addEventListener(ResultEvent.RESULT,requestResultHandle);
			_remoteOjbect.addEventListener(FaultEvent.FAULT,requestFaultHandle);
		}
		public function set destination(value:String):void{
			_remoteOjbect.destination = value;
		}
		public function set showBusyCursor(value:Boolean):void{
			_remoteOjbect.showBusyCursor = value;
		}
		public function set source(value:String):void{
			_remoteOjbect.source = value;	
		}
		private function requestFaultHandle(e:FaultEvent):void{
			//trace("服务器连接出错！  " + Service.url);
			if (_faultHandle)
			{
				_faultHandle(e.message);
			}
		}
		private function requestResultHandle(e:ResultEvent):void{
			if(_resultHandle){
				if(_data)
					_resultHandle(e.result,_data);
				else
					_resultHandle(e.result);
			}
		}
		override public function request(methodName:String,... args:Array):void{
			var _token:AsyncToken;
			switch(args.length){
				case 0:
					_token = _remoteOjbect.getOperation(methodName).send();
					break;
				case 1:
					_token = _remoteOjbect.getOperation(methodName).send(args[0]);
					break;
				case 2:
					_token = _remoteOjbect.getOperation(methodName).send(args[0],args[1]);
					break;
				case 3:
					_token = _remoteOjbect.getOperation(methodName).send(args[0],args[1],args[2]);
					break;
				case 4:
					_token = _remoteOjbect.getOperation(methodName).send(args[0],args[1],args[2],args[3]);
					break;
				case 5:
					_token = _remoteOjbect.getOperation(methodName).send(args[0],args[1],args[2],args[3],args[4]);
					break;
				case 6:
					_token = _remoteOjbect.getOperation(methodName).send(args[0],args[1],args[2],args[3],args[4],args[5]);
					break;
				case 7:
					_token = _remoteOjbect.getOperation(methodName).send(args[0],args[1],args[2],args[3],args[4],args[5],args[6]);
					break;
				case 8:
					_token = _remoteOjbect.getOperation(methodName).send(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7]);
					break;
				case 9:
					_token = _remoteOjbect.getOperation(methodName).send(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8]);
					break;
				case 10:
					_token = _remoteOjbect.getOperation(methodName).send(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9]);
					break;
			}
		}
	}
}